(ns eventsmashup.template2
   (:use [net.cgrand.enlive-html :as html]
         [ring.adapter.jetty :only [run-jetty] :as jetty]
         [ring.util.response :only [response]]
         [compojure.core :only [defroutes GET POST wrap!]]
         [eventsmashup.data])
   (:require [compojure.route :as route]))

;;site
(def site-name "Events Mashup")


;; getting pages content
(defn page-content [page]
   (html/select (html/html-resource (str "eventsmashup/" page "-content.html")) [:#page]))

;; snippets
;; sidebar snippet

(html/defsnippet sidebar "eventsmashup/index.html" [:#sidebar] 
   [{:keys [sidebar-box-one sidebar-box-two sidebar-box-three]}]
   [:#sidebar-box-one] (html/content sidebar-box-one)
   [:#sidebar-box-two] (html/content sidebar-box-two)
         [:#sidebar-box-three] (html/content sidebar-box-three))


;; navigation current item

(html/defsnippet navigation-current "eventsmashup/index.html" [:#nav]
   [current]
   [(attr= :href (str "/" current))] (html/set-attr :class "current"))


;; post snipets
(html/defsnippet post-model "eventsmashup/index.html" [:.post]
   [{:keys [title date month author body link]}]
   [:.post :.title :a] (html/do-> (html/set-attr :name link) (html/content title))
   [:.post :.date] (html/content date)
   [:.post :.month] (html/content month)
   [:.post :.postinfo :em] (html/content author)
   [:.post :.post-body] (html/html-content body))

;; latest posts

(html/defsnippet latest-link "eventsmashup/index.html" [:#latest :li]
   [{:keys [title link]}]
   [:a] (html/do-> (html/set-attr :href (str "/#" link)) (html/content title)))

;; user details

;;sidebar defs

(defn home-sidebar []
   (sidebar {:sidebar-box-one (make-ul-with-h4 "FonForum-Master" (ff-master-top5-headlines))
             :sidebar-box-two (make-ul-with-h4 "FON Master" (fon-master-top5-headlines))})) 

;; tempate 
;; layout

(html/deftemplate layout "eventsmashup/index.html"
   [{:keys [main sidebar title current latest]}]
   [:title] (html/content title)   
   [:#main]  (maybe-content main)
   [:#sidebar] (html/substitute (sidebar))
   [:#nav] (html/substitute (navigation-current current))
   [:#latest] (html/content latest))



;; pages
(defn home []
   (layout {:main (map #(post-model %) posts)
            :sidebar home-sidebar
            :title site-name
            :current ""
            :latest (map #(latest-link %) posts)}))


